package com.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.v4.view.ViewPager.LayoutParams;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;

import com.mywork.R;


public class HeaderImageDialog
        extends
        Dialog
        implements
        View.OnClickListener {
    private View btnCamera, btnLocal;
    private Context context;

    private OnUserinfoMenuClickListener menuClickListener;

    public HeaderImageDialog(Context context, OnUserinfoMenuClickListener menuClickListener) {
        super(context, R.style.common_dialog);
        this.menuClickListener = menuClickListener;
        this.context = context;
        setCanceledOnTouchOutside(true);
        findViews();
        setListeners();
        getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        getWindow().setGravity(Gravity.BOTTOM);
        getWindow().setWindowAnimations(android.R.style.Animation_InputMethod);
    }

    private void findViews() {
        View view = LayoutInflater.from(context).inflate(R.layout.userinfo_change_logo_dialog, null);
        btnCamera = view.findViewById(R.id.userinfo_dialog_camera);
        btnLocal = view.findViewById(R.id.userinfo_dialog_local);

        setContentView(view);
    }

    private void setListeners() {
        btnCamera.setOnClickListener(this);
        btnLocal.setOnClickListener(this);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_MENU) {
            this.dismiss();
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onClick(View v) {
        this.dismiss();
        if (v == btnCamera) {
            this.dismiss();
            menuClickListener.openCamera();
        } else if (v == btnLocal) {
            this.dismiss();
            menuClickListener.openLocal();

        }
    }

    public interface OnUserinfoMenuClickListener {
        void openCamera();

        void openLocal();
    }
}
